#!/usr/bin/env bash

. $(dirname $0)/util
set -eu

: ${PLATFORMS=}
: ${BUILDKITD_TAGS=}

buildkitdTagsFlags=""
if [ -n "$BUILDKITD_TAGS" ]; then
  buildkitdTagsFlags="--build-arg=BUILDKITD_TAGS=\"$BUILDKITD_TAGS\""
fi

platformFlag=""
if [ -n "$PLATFORMS" ]; then
  platformFlag="--platform=$PLATFORMS"
fi

buildxCmd build $platformFlag $buildkitdTagsFlags \
  --target "binaries" \
  --output "type=local,dest=./bin/" \
  .
